package com.xsp.controller;

import com.xsp.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xsp
 * @date 2024/2/25
 * @desc
 */
@Controller
public class LoginController {
    @GetMapping("login")
    public String login() {
        return "login";
    }

    @PostMapping("login")
    public String login(HttpServletRequest request, User user) {
        if ("admin".equals(user.getUsername()) && "123456".equals(user.getPassword())){
            // 保存登录凭证
            request.getSession().setAttribute("loginUser",user);
            return "redirect:/user2/list";
        }else{
            return "redirect:/login";
        }
    }
}
